home *** CD-ROM | disk | FTP | other *** search
- Path: news2.aimnet.com!usenet
- From: gander@aimnet.com (Geoffrey Anderson)
- Newsgroups: comp.lang.c
- Subject: Re: Processor Fault!!??
- Date: Mon, 29 Jan 1996 07:42:17 GMT
- Organization: Aimnet Information Services
- Message-ID: <310c792e.4231971@news2.aimnet.com>
- References: <Pine.A32.3.91j.960128010358.43648E-100000@homer23.u.washington.edu>
- NNTP-Posting-Host: dial-milp-28.iway.aimnet.com
- X-Newsreader: Forte Agent .99c/16.141
-
- "Q. Sun" <quanger@u.washington.edu> wrote:
-
- >
- >I was doing some examples off a text we are using and I am having
- >problems with it. The chapter is on arrays and I type in and ran the
- >programs in the text. When I ran it using Turbo C++ 3.1 it gave a nasty
- >General Protection Fault and stating it's the processor's fault! It also
- >said things like "0x211F:0x00BE Processor Fault." In Windows 95 it total
- >crashed! But in Windows for Workgroups 3.11, it recovered a
- >couple of runs until it eventually kicked me out to DOS.
- >
- >I'm running a Pentium 120 with 16megs of RAM. Do I have one of those old
- >faulty Pentiums? My system is about one week new.
- >
- >The code example is EXACTLY as follows:
- >
- >/* Program to convert a postivie interger to another base */
- >#include <stdio.h>
- >main ()
- >{
- > char base_digits[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
- > '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
- > int converted_number[64];
- > int number_to_convert;
- ^^^ should be long since you scan for a long signed
- integer in your scanf...
- > int next_digit, base, index = 0;
- >
- > /* get the number and the base */
- >
- > printf ("Number to be converted? ");
- > scanf ("%ld", &number_to_convert);
- > printf ("Base? ");
- > scanf ("%i", &base);
- >
- > /* convert to the indicated base */
- >
- > do
- > {
- > converted_number[index] = number_to_convert % base;
- > ++index;
- > number_to_convert = number_to_convert / base;
- > }
- > while ( number_to_convert != 0);
- >
- Careful examination says that you have the index incremented
- so you are actually pointing to an un-known array element. When you
- look up the digit, you quite probably have a wrong pointer and BANG it
- goes crash!
-
- Try adding a index-- before the for loop....
-
- >
- /* display the results in reverse order */
- >
- > printf ("Converted number = ");
- >
- > for ( index; index >= 0; --index )
- > {
- > next_digit = converted_number[index];
- > printf("%c", base_digits[next_digit]);
- > }
- >
- > printf ("\n");
- >
- >}
- >
- >/* Code ends here */
- >
- >
- >
-
-